#include "GY_GraphicsCrown.h"
#include <QPainter>
#include<QtMath>
GY_GraphicsCrown::GY_GraphicsCrown(const QString &guid, QGraphicsItem *parent)
    :GY_BasicsGraphicsObject(guid,this,parent)
{
    //图元类型
    GY_Object::setUserData(GY_ENUM::ClassType,QVariant("Crown"));
    initializationPropertyInfo();
    updataPen();
    updataBrush();
    updateDraw();
    QMap<QVariant,QPointF> editPoints = {
        {"OuterRadiusPoint",m_PropertyInfoMap["OuterRadiusPoint"].propertyValue.toPointF()},
        {"InnerRadiusPoint",m_PropertyInfoMap["InnerRadiusPoint"].propertyValue.toPointF()}
    };
    this->setPen(QColor(Qt::green));
    this->setEditPointF(editPoints);
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
}

GY_GraphicsCrown::GY_GraphicsCrown(const QString &guid,const QPointF &position,const qreal &startAngele,
                                   const qreal &endAngele,const qreal &innerRaduis,const qreal &outerRaduis,QGraphicsItem *parent)
    :GY_BasicsGraphicsObject(guid,this,parent)
{
    //图元类型
    GY_Object::setUserData(GY_ENUM::ClassType,QVariant("Crown"));
    initializationPropertyInfo();
    updataPen();
    updataBrush();
    m_PropertyInfoMap["Position"].propertyValue=position;
    m_PropertyInfoMap["StartAngle"].propertyValue=startAngele;
    m_PropertyInfoMap["EndAngle"].propertyValue=endAngele;
    m_PropertyInfoMap["InnerRadius"].propertyValue=innerRaduis;
    m_PropertyInfoMap["OuterRadius"].propertyValue=outerRaduis;
    updateDraw();
    calculateInnerRadiusPointPosition();
    calculateOuterRadiusPointPosition();
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
}
/**
 * @brief initializationPropertyInfo 初始化属性信息
 */
void GY_GraphicsCrown::initializationPropertyInfo()
{
    GY_PropertyInfo IsOpen(this);
    IsOpen.propertyName = "IsOpen";
    IsOpen.propertyValue = false;
    IsOpen.updateType = NotUpdate;
    IsOpen.propertyType = BoolPropertyType;
    IsOpen.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateIsOpen;
    m_PropertyInfoMap.insert("IsOpen",IsOpen);
    m_PropertyInfoMap[IsOpen.propertyName].setConnect();

    //位置
    GY_PropertyInfo positonPropertyInfo(this);
    positonPropertyInfo.propertyName="Position";
    positonPropertyInfo.propertyValue=QPointF(0,0);
    positonPropertyInfo.updateType = MoveUpdate|PointOfRelative|Update;
    positonPropertyInfo.propertyType = PointPropertyType;
    positonPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateCirlePoint;
    m_PropertyInfoMap.insert(positonPropertyInfo.propertyName,positonPropertyInfo);
    m_PropertyInfoMap[positonPropertyInfo.propertyName].setConnect();
    //开始角度
    GY_PropertyInfo startAnglePropertyInfo(this);
    startAnglePropertyInfo.propertyName="StartAngle";
    startAnglePropertyInfo.propertyValue=0.0;
    startAnglePropertyInfo.updateType = Update|OrdinaryAttributes;
    startAnglePropertyInfo.propertyType = DoublePropertyType;
    startAnglePropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateStartAngle;
    m_PropertyInfoMap.insert(startAnglePropertyInfo.propertyName,startAnglePropertyInfo);
    m_PropertyInfoMap[startAnglePropertyInfo.propertyName].setConnect();

    //经过角度
    GY_PropertyInfo passAnglePropertyInfo(this);
    passAnglePropertyInfo.propertyName="EndAngle";
    passAnglePropertyInfo.propertyValue=180.0;
    passAnglePropertyInfo.updateType = Update|OrdinaryAttributes;
    passAnglePropertyInfo.propertyType = DoublePropertyType;
    passAnglePropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateEndAngele;
    m_PropertyInfoMap.insert(passAnglePropertyInfo.propertyName,passAnglePropertyInfo);
    m_PropertyInfoMap[passAnglePropertyInfo.propertyName].setConnect();

    //内圈半径
    GY_PropertyInfo innerRadiusPropertyInfo(this);
    innerRadiusPropertyInfo.propertyName="InnerRadius";
    innerRadiusPropertyInfo.propertyValue=100.0;
    innerRadiusPropertyInfo.updateType = Update|OrdinaryAttributes;
    innerRadiusPropertyInfo.propertyType = DoublePropertyType;
    innerRadiusPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateInnerRadius;
    m_PropertyInfoMap.insert(innerRadiusPropertyInfo.propertyName,innerRadiusPropertyInfo);
    m_PropertyInfoMap[innerRadiusPropertyInfo.propertyName].setConnect();

    //外圈半径
    GY_PropertyInfo outerRadiusPropertyInfo(this);
    outerRadiusPropertyInfo.propertyName="OuterRadius";
    outerRadiusPropertyInfo.propertyValue=120.0;
    outerRadiusPropertyInfo.updateType = Update|OrdinaryAttributes;
    outerRadiusPropertyInfo.propertyType = DoublePropertyType;
    outerRadiusPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateOuterRadius;
    m_PropertyInfoMap.insert(outerRadiusPropertyInfo.propertyName,outerRadiusPropertyInfo);
    m_PropertyInfoMap[outerRadiusPropertyInfo.propertyName].setConnect();

    //外圈半径点
    GY_PropertyInfo outerRadiusPointPropertyInfo(this);
    outerRadiusPointPropertyInfo.propertyName="OuterRadiusPoint";
    outerRadiusPointPropertyInfo.propertyValue=QPointF(100,0);
    outerRadiusPointPropertyInfo.updateType = NotUpdate;
    outerRadiusPointPropertyInfo.propertyType = PointPropertyType;
    outerRadiusPointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateOuterRadiusPoint;
    m_PropertyInfoMap.insert(outerRadiusPointPropertyInfo.propertyName,outerRadiusPointPropertyInfo);
    m_PropertyInfoMap[outerRadiusPointPropertyInfo.propertyName].setConnect();

    //内圈半径点
    GY_PropertyInfo innerRadiusPointPropertyInfo(this);
    innerRadiusPointPropertyInfo.propertyName="InnerRadiusPoint";
    innerRadiusPointPropertyInfo.propertyValue=QPointF(-120,0);
    innerRadiusPointPropertyInfo.updateType = NotUpdate;
    innerRadiusPointPropertyInfo.propertyType = PointPropertyType;
    innerRadiusPointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateInnerRadiusPoint;
    m_PropertyInfoMap.insert(innerRadiusPointPropertyInfo.propertyName,innerRadiusPointPropertyInfo);
    m_PropertyInfoMap[innerRadiusPointPropertyInfo.propertyName].setConnect();

    /********************************************公共属性***********************************************/
    GY_PropertyInfo ObjectName(this);
    ObjectName.propertyName = "ObjectName";
    ObjectName.propertyValue = QString();
    ObjectName.updateType = Update|OrdinaryAttributes;
    ObjectName.propertyType = QStringPropertyType;
    ObjectName.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateObjectName;
    m_PropertyInfoMap.insert("ObjectName",ObjectName);
    m_PropertyInfoMap[ObjectName.propertyName].setConnect();

    GY_PropertyInfo penOpacity(this);
    penOpacity.propertyName = "PenOpacity";
    penOpacity.propertyValue = 1;
    penOpacity.updateType = Update|OrdinaryAttributes;
    penOpacity.propertyType = QrealPropertyType;
    penOpacity.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updatePenOpacity;
    m_PropertyInfoMap.insert(penOpacity.propertyName,penOpacity);
    m_PropertyInfoMap[penOpacity.propertyName].setConnect();

    GY_PropertyInfo IsOutLined(this);
    IsOutLined.propertyName = "IsOutlined";
    IsOutLined.propertyValue = true;
    IsOutLined.updateType = Update|OrdinaryAttributes;
    IsOutLined.propertyType = BoolPropertyType;
    IsOutLined.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateIsOutLined;
    m_PropertyInfoMap.insert("IsOutlined",IsOutLined);
    m_PropertyInfoMap[IsOutLined.propertyName].setConnect();

    GY_PropertyInfo LineStyle(this);
    LineStyle.propertyName = "LineStyle";
    /*
     *LineStyle属性的数据
     * QVector<qreal>中index(0)是Qt::PenCapStyle、Qt::PenJoinStyle与Qt::PenStyle的组合,index(1)为线条粗细，之后是自定义钢笔样式的数据 */
    QVector<qreal> varStyle;
    int style = Qt::SquareCap|Qt::BevelJoin|Qt::CustomDashLine;
    varStyle<<style<<2<<3<<2<<4<<5<<6<<7;
    LineStyle.propertyValue = QVariant::fromValue(varStyle);
    LineStyle.updateType = Update|OrdinaryAttributes;
    LineStyle.propertyType = LineStylePropertyType;
    LineStyle.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateLineStyle;
    m_PropertyInfoMap.insert(LineStyle.propertyName,LineStyle);
    m_PropertyInfoMap[LineStyle.propertyName].setConnect();

    GY_PropertyInfo penColor(this);
    penColor.propertyName = "PenColor";
    penColor.propertyValue = QColor(255,255,255);
    penColor.updateType = Update|OrdinaryAttributes;
    penColor.propertyType = ColorPropertyType;
    penColor.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updatePenColor;
    m_PropertyInfoMap.insert(penColor.propertyName,penColor);
    m_PropertyInfoMap[penColor.propertyName].setConnect();

    GY_PropertyInfo penAttributes(this);
    penAttributes.propertyName = "PenAttributes";
    penAttributes.propertyValue = false;
    penAttributes.updateType = Update|OrdinaryAttributes;
    penAttributes.propertyType = BoolPropertyType;
    penAttributes.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updatePenAttributes;
    m_PropertyInfoMap.insert(penAttributes.propertyName,penAttributes);
    m_PropertyInfoMap[penAttributes.propertyName].setConnect();

    GY_PropertyInfo isVisible(this);
    isVisible.propertyName = "IsVisible";
    isVisible.propertyValue = true;
    isVisible.updateType = Update|OrdinaryAttributes;
    isVisible.propertyType = BoolPropertyType;
    isVisible.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateIsVisible;
    m_PropertyInfoMap.insert(isVisible.propertyName,isVisible);
    m_PropertyInfoMap[isVisible.propertyName].setConnect();

    GY_PropertyInfo isFilled(this);
    isFilled.propertyName = "IsFilled";
    isFilled.propertyValue = true;
    isFilled.updateType = Update|OrdinaryAttributes;
    isFilled.propertyType = BoolPropertyType;
    isFilled.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateIsFilled;
    m_PropertyInfoMap.insert("IsFilled",isFilled);
    m_PropertyInfoMap[isFilled.propertyName].setConnect();

    GY_PropertyInfo fillOpacity(this);
    fillOpacity.propertyName = "FillOpacity";
    fillOpacity.propertyValue = 1;
    fillOpacity.updateType = Update|OrdinaryAttributes;
    fillOpacity.propertyType = QrealPropertyType;
    fillOpacity.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateFillOpacity;
    m_PropertyInfoMap.insert("FillOpacity",fillOpacity);
    m_PropertyInfoMap[fillOpacity.propertyName].setConnect();

    GY_PropertyInfo pattern(this);
    pattern.propertyName = "Pattern";
    //Pattern填充图案数据
    QVector<QPoint> points;
    points << QPoint(0,1)<< QPoint(2,1)<< QPoint(3,1) << QPoint(5,1)<< QPoint(5,15) << QPoint(14,8);
//    pattern.propertyValue = QVariant::fromValue(points);
    pattern.propertyValue = QVariant();
    pattern.updateType = Update|OrdinaryAttributes;
    pattern.propertyType = PatternPropertyType;
    pattern.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updatePattern;
    m_PropertyInfoMap.insert("Pattern",pattern);
    m_PropertyInfoMap[pattern.propertyName].setConnect();

    GY_PropertyInfo fillGradient(this);
    fillGradient.propertyName = "FillGradient";
    //FillGradient渐变数据
    int gradientSpread = QGradient::ReflectSpread;//指定如何填充渐变之外的区域
    QColor colorStart = QColor(0,255,0);//开始颜色
    QColor colorStop = QColor(0,0,255);//结束颜色
    int gradientType = QGradient::LinearGradient;//指定渐变的类型
    QPointF pointFStart = QPointF(0,0);//开始的坐标或中心点坐标
    QPointF pointFStop = QPointF(25,25);//结束的坐标或径向梯度的焦点坐标
    qreal centerRadius = 100;//中心半径
    qreal focalRadius = 100;//径向梯度的焦点半径
    QVector<qreal> varGradientStyle;
    varGradientStyle<<gradientSpread<<colorStart.rgb()<<colorStop.rgb()<<gradientType<<pointFStart.x()
                   <<pointFStart.y()<<pointFStop.x()<<pointFStop.y()<<centerRadius<<focalRadius;
    fillGradient.propertyValue = QVariant::fromValue(varGradientStyle);
    fillGradient.updateType = Update|OrdinaryAttributes;
    fillGradient.propertyType = FillGradientPropertyType;
    fillGradient.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateFillGradient;
    m_PropertyInfoMap.insert("FillGradient",fillGradient);
    m_PropertyInfoMap[fillGradient.propertyName].setConnect();

    GY_PropertyInfo fillColor(this);
    fillColor.propertyName = "FillColor";
    fillColor.propertyValue = QColor(255,255,255);
    fillColor.updateType = Update|OrdinaryAttributes;
    fillColor.propertyType = FillStylePropertyType;
    fillColor.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateFillColor;
    m_PropertyInfoMap.insert("FillColor",fillColor);
    m_PropertyInfoMap[fillColor.propertyName].setConnect();

    GY_PropertyInfo fillStyle(this);
    fillStyle.propertyName = "FillStyle";
    fillStyle.propertyValue = true;
    fillStyle.updateType = Update|OrdinaryAttributes;
    fillStyle.propertyType = BoolPropertyType;
    fillStyle.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateFillStyle;
    m_PropertyInfoMap.insert("FillStyle",fillStyle);
    m_PropertyInfoMap[fillStyle.propertyName].setConnect();

    GY_PropertyInfo fillAttributes(this);
    fillAttributes.propertyName = "FillAttributes";
    fillAttributes.propertyValue = false;
    fillAttributes.updateType = Update|OrdinaryAttributes;
    fillAttributes.propertyType = BoolPropertyType;
    fillAttributes.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateFillAttributes;
    m_PropertyInfoMap.insert("FillAttributes",fillAttributes);
    m_PropertyInfoMap[fillAttributes.propertyName].setConnect();

    GY_PropertyInfo isAntialiased(this);
    isAntialiased.propertyName = "IsAntialiased";
    isAntialiased.propertyValue = false;
    isAntialiased.updateType = Update|OrdinaryAttributes;
    isAntialiased.propertyType = BoolPropertyType;
    isAntialiased.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsCrown::updateIsAntialiased;
    m_PropertyInfoMap.insert("IsAntialiased",isAntialiased);
    m_PropertyInfoMap[isAntialiased.propertyName].setConnect();

}
/**
 * @brief UpdateDraw 更新绘制
 */
void GY_GraphicsCrown::updateDraw()
{
    QPointF centerPoint= m_PropertyInfoMap.value("Position").propertyValue.toPointF();
    qreal startAngle=m_PropertyInfoMap.value("StartAngle").propertyValue.toDouble();
    qreal endAngle=m_PropertyInfoMap.value("EndAngle").propertyValue.toDouble();
    qreal innerRadius=m_PropertyInfoMap.value("InnerRadius").propertyValue.toDouble();
    qreal outerRadius=m_PropertyInfoMap.value("OuterRadius").propertyValue.toDouble();
    QPointF innerDiffPoint=QPointF(centerPoint.x()-innerRadius,centerPoint.y()-innerRadius);
    QPointF outerDiffPoint=QPointF(centerPoint.x()-outerRadius,centerPoint.y()-outerRadius);

    if(innerRadius==outerRadius) {
        m_PropertyInfoMap["IsOpen"].propertyValue = true;
        updataBrush();
        QPainterPath path;
        path.arcMoveTo(innerDiffPoint.x(),innerDiffPoint.y(),2*innerRadius,2*innerRadius,-startAngle);
        path.arcTo(innerDiffPoint.x(),innerDiffPoint.y(),2*innerRadius,2*innerRadius,-startAngle,
                   -((endAngle-startAngle)<0?(360+(endAngle-startAngle)):(endAngle-startAngle)));
        this->setPath(path);
        return;
    }
    m_PropertyInfoMap["IsOpen"].propertyValue = false;
    updataBrush();
    //第一种绘制方法(绘制外圈减除内圈)
    //判定内外圈大小
    if(innerRadius>outerRadius)
    {
        innerRadius+=outerRadius;
        outerRadius=innerRadius-outerRadius;
        innerRadius-=outerRadius;
        innerDiffPoint=innerDiffPoint+outerDiffPoint;
        outerDiffPoint=innerDiffPoint-outerDiffPoint;
        innerDiffPoint=innerDiffPoint-outerDiffPoint;
    }
    QPainterPath innerPath;
    QPainterPath outerPath;
    outerPath.moveTo(centerPoint);
    outerPath.arcTo(outerDiffPoint.x(),outerDiffPoint.y(),2*outerRadius,2*outerRadius,-startAngle,
                    -((endAngle-startAngle)<0?(360+(endAngle-startAngle)):(endAngle-startAngle)));
    outerPath.closeSubpath();

    innerPath.addEllipse(centerPoint,innerRadius,innerRadius);
    innerPath.closeSubpath();
    this->setPath(outerPath-innerPath);
/*
    //第二种会中方法(逐根线条绘制)
    qreal sweptAngle = endAngle-startAngle;
    if(startAngle>endAngle) {
        sweptAngle = 360-(startAngle-endAngle);
    }
    QPainterPath path;
    QPointF innerRadiusStartPoint=precalculatedPosition(centerPoint,innerRadius,startAngle);
    QPointF innerRadiusEndPoint=precalculatedPosition(centerPoint,innerRadius,endAngle);
    QPointF outerRadiusStartPoint=precalculatedPosition(centerPoint,outerRadius,startAngle);
    QPointF outerRadiusEndPoint=precalculatedPosition(centerPoint,outerRadius,endAngle);
    path.moveTo(innerRadiusStartPoint);
    path.lineTo(outerRadiusStartPoint);
//    path.moveTo(centerPoint);
    path.arcMoveTo(outerDiffPoint.x(),outerDiffPoint.y(),2*outerRadius,2*outerRadius,-startAngle);
    path.arcTo(outerDiffPoint.x(),outerDiffPoint.y(),2*outerRadius,2*outerRadius,-startAngle,-(sweptAngle));
    path.moveTo(outerRadiusEndPoint);
    path.lineTo(innerRadiusEndPoint);
//    path.moveTo(centerPoint);
    path.arcMoveTo(innerDiffPoint.x(),innerDiffPoint.y(),2*innerRadius,2*innerRadius,-endAngle);
    path.arcTo(innerDiffPoint.x(),innerDiffPoint.y(),2*innerRadius,2*innerRadius,-endAngle,(sweptAngle));
    path.closeSubpath();

    this->setPath(path);
*/
}
/**
 * @brief updateCirlePoint  更新中心点
 * @param name 属性名称
 * @param value 中心点位置
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateCirlePoint(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=this->mapFromScene(value.toPointF());
    this->setCenterPointF(this->mapFromScene(value.toPointF()));
    updateDraw();
    calculateInnerRadiusPointPosition();
    calculateOuterRadiusPointPosition();
    return true;
}
/**
 * @brief updateStartAngele 更新开始角度
 * @param name 属性名称
 * @param value 开始角度
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateStartAngle(const QString &name, const QVariant &value)
{
    if(!value.canConvert<double>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value.toDouble();
    updateDraw();
    calculateInnerRadiusPointPosition();
    return true;
}
/**
 * @brief updateEndAngele 更新结束角度
 * @param name 属性名称
 * @param value 结束角度
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateEndAngele(const QString &name, const QVariant &value)
{
    if(!value.canConvert<double>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value.toDouble();
    updateDraw();
    calculateOuterRadiusPointPosition();
    return true;
}
/**
 * @brief updateInnerRadius 更新内圈半径
 * @param name 属性名称
 * @param value 内圈半径
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateInnerRadius(const QString &name, const QVariant &value)
{
    if(!value.canConvert<double>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value.toDouble();
    updateDraw();
    calculateInnerRadiusPointPosition();
    return true;
}
/**
 * @brief updateOuterRadius 更新外圈半径
 * @param name 属性名称
 * @param value 外圈半径
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateOuterRadius(const QString &name, const QVariant &value)
{
    if(!value.canConvert<double>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value.toDouble();
    updateDraw();
    calculateOuterRadiusPointPosition();
    return true;
}
/**
 * @brief updateOuterRadiusPoint 更新外圈半径点
 * @param name 属性名称
 * @param value 外圈半径点位置
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateOuterRadiusPoint(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    QPointF point=this->mapFromScene(value.toPointF());
    //基于圆心的偏移坐标
    QPointF diffPoint=point-m_PropertyInfoMap.value("Position").propertyValue.toPointF();
    qreal pointRadius=qSqrt(qPow(qAbs(diffPoint.x()),2)+qPow(qAbs(diffPoint.y()),2));
    m_PropertyInfoMap["OuterRadius"].propertyValue=pointRadius;
    qreal pointAngle=precalculatedAngle(m_PropertyInfoMap.value("Position").propertyValue.toPointF(),point);
    m_PropertyInfoMap["EndAngle"].propertyValue=pointAngle;
    updateDraw();
    m_PropertyInfoMap[name].propertyValue=point;
    this->setEditPointF(name,point);
    return true;
}
/**
 * @brief updateInnerRadiusPoint 更新内圈半径点
 * @param name 属性名称
 * @param value 内圈半径点位置
 * @return 是否更新成功
 */
bool GY_GraphicsCrown::updateInnerRadiusPoint(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    QPointF point=this->mapFromScene(value.toPointF());
    //基于圆心的偏移坐标
    QPointF diffPoint=point-m_PropertyInfoMap.value("Position").propertyValue.toPointF();
    qreal pointRadius=qSqrt(qPow(qAbs(diffPoint.x()),2)+qPow(qAbs(diffPoint.y()),2));
    m_PropertyInfoMap["InnerRadius"].propertyValue=pointRadius;
    qreal pointAngle=precalculatedAngle(m_PropertyInfoMap.value("Position").propertyValue.toPointF(),point);
    m_PropertyInfoMap["StartAngle"].propertyValue=pointAngle;
    updateDraw();
    m_PropertyInfoMap[name].propertyValue=point;
    this->setEditPointF(name,point);
    return true;
}
/**
 * @brief precalculatedPosition 计算点位置
 * @param centerPoint  中心点位置
 * @param radius 半径
 * @param angele 角度
 * @return 计算得到的点位置
 */
QPointF GY_GraphicsCrown::precalculatedPosition(const QPointF &centerPoint,const double radius,const double angele)
{
    qreal radian=qDegreesToRadians(angele); //弧度
    QPointF resultPoint;
    resultPoint.setX(cos(radian)*radius);
    resultPoint.setY(sin(radian)*radius);
    resultPoint+=centerPoint;
    return resultPoint;
}
/**
 * @brief precalculatedAngle 计算相对中心点的角度
 * @param centerPoint 中心点
 * @param calculatePoint 计算点
 * @return 角度
 */
qreal GY_GraphicsCrown::precalculatedAngle(const QPointF &centerPoint,const QPointF &calculatePoint)
{
    //基于圆心的偏移坐标
    QPointF diffPoint=calculatePoint-centerPoint;
    qreal pointAngle=qRadiansToDegrees(qAtan2(diffPoint.y(),diffPoint.x()));
    if(diffPoint.y()<0)
    {
        pointAngle+=360;
    }
    return pointAngle;
}
/**
 * @brief calculateInnerRadiusPointPosition
 * 计算内圈半径点位置
 */
void GY_GraphicsCrown::calculateInnerRadiusPointPosition()
{
    QPointF  innerRadiusPoint=precalculatedPosition(m_PropertyInfoMap["Position"].propertyValue.toPointF(),m_PropertyInfoMap["InnerRadius"].propertyValue.toDouble(),m_PropertyInfoMap["StartAngle"].propertyValue.toDouble());
    m_PropertyInfoMap["InnerRadiusPoint"].propertyValue=innerRadiusPoint;
    this->setEditPointF("InnerRadiusPoint",innerRadiusPoint);
}
/**
 * @brief calculateOuterRadiusPointPosition
 * 计算外圈半径点位置
 */
void GY_GraphicsCrown::calculateOuterRadiusPointPosition()
{
    QPointF  outerRadiusPoint=precalculatedPosition(m_PropertyInfoMap["Position"].propertyValue.toPointF(),m_PropertyInfoMap["OuterRadius"].propertyValue.toDouble(),m_PropertyInfoMap["EndAngle"].propertyValue.toDouble());
    m_PropertyInfoMap["OuterRadiusPoint"].propertyValue=outerRadiusPoint;
    this->setEditPointF("OuterRadiusPoint",outerRadiusPoint);
}

